package com.caigou.modules.tools.adapter

import android.view.View
import android.widget.Button
import android.widget.LinearLayout
import android.widget.ProgressBar
import com.caigou.modules.tools.R
import com.caigou.modules.tools.bean.ActiveItemBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * @author #Suyghur.
 * Created on 2021/11/03
 */
class TaskListAdapter(private val dataset: MutableList<ActiveItemBean>) :
    BaseQuickAdapter<ActiveItemBean, BaseViewHolder>(R.layout.item_active_task_list, dataset) {

    override fun convert(holder: BaseViewHolder, item: ActiveItemBean) {
        holder.setText(R.id.item_active_task_list_tv_name, item.taskName)
        holder.setText(R.id.item_active_task_list_tv_desc, item.taskDesc)
        if (item.completeCondition == 0) {
            holder.getView<LinearLayout>(R.id.item_active_task_list_ll_process).visibility = View.GONE
        } else {
            holder.getView<LinearLayout>(R.id.item_active_task_list_ll_process).visibility = View.VISIBLE
            holder.setText(R.id.item_active_task_list_tv_num, item.taskProgress.toString())
            holder.setText(R.id.item_active_task_list_tv_total, "/${item.completeCondition}")
            holder.getView<ProgressBar>(R.id.item_active_task_list_process_bar).max = item.completeCondition
            holder.getView<ProgressBar>(R.id.item_active_task_list_process_bar).progress = item.taskProgress
        }

        holder.getView<Button>(R.id.item_active_task_list_btn).text = when (item.status) {
            0 -> "未完成"
            1 -> "待领取"
            2 -> "已完成"
            3 -> "已结束"
            else -> ""
        }
        holder.getView<View>(R.id.item_active_task_v).visibility = if (holder.position == dataset.size - 1) {
            View.GONE
        } else {
            View.VISIBLE
        }
    }
}